//-----------------------------------------------------------------------
// <copyright file="Role.cs" company="Procure Development">
//     Copyright (c) Procure Development. All rights reserved.
// </copyright>
// <author>Victor Procure</author>
//-----------------------------------------------------------------------

using System.Linq;
using MongoDb.EntityFramework;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Driver;

namespace SManagement.Models
{
    public class Role
    {
        #region Instance Properties

        [BsonId]
        public ObjectId _id { get; set; }

        public string Description { get; set; }

        public ObjectId? RefJurisdictionId { get; set; }

        #endregion Instance Properties

        public static bool HasRole(string description, ObjectId PersonId, ObjectId OrganizationId)
        {
            var type = MongoDbContext.Current.All<OrganizationPersonRole>().Where(s => s.PersonId == PersonId && s.OrganizationId == OrganizationId).ToList();

            return (type.Count > 0);
        }
    }

    public static class RoleHelpers
    {
        public static bool HasRole(this Person person, string description, ObjectId organizationId)
        {
            return Role.HasRole(description, person._id, organizationId);
        }
    }
}